package common.kingdee.cas;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import common.kingdee.domain.KingdeeUser;
import common.security.domain.repositoryInterface.UserRepository;

public class CasUserDetailsService implements UserDetailsService {

	@Autowired
	private UserRepository<KingdeeUser> userRepository;

	@Override
	public KingdeeUser loadUserByUsername(String username) throws UsernameNotFoundException {
		if (username != null) {
			Set<KingdeeUser> users = userRepository.getAllEnabledUsers();
			for (KingdeeUser user : users) {
				if (username.trim().equals(user.getUsername())) {
					return user;
				}
			}
		}
		return null;
	}
}
